<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8" isELIgnored="false"%>
<%@ include file="/WEB-INF/views/shared/taglib.jsp"%>
<%
	request.setAttribute("modelConfigPath", "purchase");
%>
<%@ include file="/WEB-INF/views/shared/master/contentHeader.jsp"%>
	

<t:panel cssClass="panel-flat form-detailed" customBody="true" customHead="true">
    <div class="detailed-navbar-content panel-body">
    	
        <t:form modelAttribute="purchase" action="/purchase/purchase/save" method="post" cssClass="form-horizontal">
            <div class="hide">
                <t:hidden path="purchaseId"/>
                <t:hidden path="deleteMark"/>
                
            </div>
            <div class="panel-header" style="height:50px;margin:0 auto  ">
            		<label  style="color:red;font-size:1.6em;margin-left:20px;margin-top:5px"><t:provider packageName="purchase" enumClassName="PurchaseState" value="${purchase.purchaseState }"/></label><label  style="font-size:1.2em;margin-left:20px">采购单号 : ${purchase.purchaseNo }</label><label style="font-size:1.2em;margin-left:20px">供应商 :  ${purchase.supplier.supplierName }	</label><label style="font-size:1.2em;margin-left:20px">采购员 : ${purchase.purchaseName }	</label><label style="font-size:1.2em;margin-left:20px">采购日期 : <fmt:formatDate value="${purchase.createDate}" type="date" dateStyle="default" pattern="YY-MM-dd HH:mm"/>	</label>				
					<button class="btn btn-custom btn-default btn-xs legitRipple btn-primary" onclick="addPurposeList()" type="button" value="editData()"><i class="icon-plus3 position-left"></i>多货品添加</button>
			</div>
		<div style="height:470px;overflow-y:auto;overflow-x:hidden;">
			<table class="cntable table table-bordered dataTable table-serveProject multi">
					<thead>
						<tr class="success" >
							<th style="width:50px">序号</th>							
							<th style="width:120px">商品编码</th>
							<th style="width:120px">商品名称</th>
							<th style="width:120px">规格</th>
							<th style="width:60px">单位</th>
							<th style="width:60px">采购数</th>
							<th style="width:60px">可分配数量</th>
							<th style="width:60px">采购单价(元)</th>
							<th style="width:60px">小计(元)</th>
							<th style="width:60px">项目分配状态</th>
							<th style="width:60px">添加明细</th>
						</tr>
					</thead>
					<tbody>
					
					<c:forEach var="purchaseCollocation" items="${purchase.purchaseCollocations}" varStatus="status">
						<tr  data-id="${purchaseCollocation.id }">
							<td>${status.index+1 }</td>
							<td>${purchaseCollocation.collocation.collocationNo }</td>
							<td>${purchaseCollocation.cargo.cargoName }</td>
							<td>${purchaseCollocation.collocation.propertyNameOne }/${purchaseCollocation.collocation.propertyNameTwo }</td>
							<td>${purchaseCollocation.cargo.unit }</td>
							<td class="name_no">${purchaseCollocation.purchaseNumber }</td>
							<td class="name_no">${purchaseCollocation.allotmentNum}</td>
							<td class="name_no">${purchaseCollocation.purchasePrice }</td>
							<td class="name_no">${purchaseCollocation.purchaseNumber*purchaseCollocation.purchasePrice }</td>
							<td style="color:#8c8c00">
								<t:provider packageName="purchase" enumClassName="AllocationState" value="${purchaseCollocation.collocationState }"/>
							</td>
							<td>
								<button class="btn btn-custom btn-default btn-xs legitRipple btn-primary" onclick="addPurpose(this)" type="button" value="editData()"><i class="icon-plus3 position-left"></i>添加</button>
							</td>
						</tr>			
					</c:forEach>
					
										
					</tbody>
					
				</table>     
			</div>
        </t:form>
    </div>

</t:panel>



<script type="text/javascript">
var purchaseCollocationIds = [];

$(function(){
	//重新进入时保持选中	
	bindClick();
	//监听点击事件后将点击对象保存进数组
	trClickListener();
	resizeEx();
	$(window).resizeend({delay : 500}, function() {
		resizeEx();
	});
});

function resizeEx(){

	$(".panel-body").height($(window).height()-22)
}
function saveData(lBtn){
	if (!$("form:first").valid()){
		return;
	}
	lBtn.start();
	$("form:first").submit();
}	

function printer(){
	var key=$("#purchaseId").val();
	top.openModal("/purchase/purchase/purchaseDetailPrint?key="+key,"purchasePrint_form","采购单打印",1200,450);
}

function reload(){
	location.reload();
}

function addPurpose(element){
	var purchaseCollocationId=$(element).parent().parent().attr("data-id");
	top.openModal("/project/purpose/detailed?purchaseCollocationId="+purchaseCollocationId+"&type="+"add","purpose_form","项目使用明细-添加",950,410);
}

function addPurposeList(){
	if(purchaseCollocationIds.length != 0){
		top.openModal("/project/purpose/purposeListDetailed?purchaseCollocationIds="+purchaseCollocationIds+"&type="+"add"+"&purchaseId="+$("#purchaseId").val(),"purpose_form","项目使用明细-添加",980,410);
	}else{
		$.showTips("请选择分配货品！",1000,"warning");
	}
}

function bindClick(){
	 for(var i=0;i<purchaseCollocationIds.length;i++){
		 $("tr[data-id="+purchaseCollocationIds[i]+"]").addClass("select-tr");
    }
} 

function trClickListener(){
	$("table tbody tr").click(function(){
		var selectedId = $(this).attr("data-id");
		console.log(selectedId);
		var position = -1;
		for(var i=0;i<purchaseCollocationIds.length;i++){
			if(purchaseCollocationIds[i] == selectedId){
				position = i;					
			}
	     }
		if(position>-1){
			purchaseCollocationIds.splice(position,1);
		}else{
			purchaseCollocationIds.push(selectedId);
		}		
	});
}

</script>
<%@ include file="/WEB-INF/views/shared/base/scripts/jqueryui.jsp"%>
<%@ include file="/WEB-INF/views/shared/master/cntable.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formtags.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formbuttons.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formpickers.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formselects.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formstyling.jsp"%>
<%@ include file="/WEB-INF/views/shared/master/dialog.jsp"%>
<%@ include file="/WEB-INF/views/shared/master/contentFooter.jsp"%>
